<template>
  <div class="patient-table-container">
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      stripe
      @sort-change="handleSortChange"
    >
      <el-table-column prop="trackCode" label="患者编号" width="120" />
      <el-table-column prop="name" label="姓名" width="100" />
      <el-table-column prop="idCard" label="身份证号" width="180" />
      <el-table-column prop="phone" label="手机号" width="120" />
      <el-table-column prop="isInitial" label="是否初诊" width="120" sortable>
        <template #default="{ row }">
          <el-tag
            :type="row.isInitial ? 'success' : 'info'"
            size="small"
            class="diagnosis-tag"
          >
            <span class="diagnosis-indicator" :class="row.isInitial ? 'diagnosis-followup' : 'diagnosis-initial'"></span>
            {{ row.isInitial ? '是' : '否' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="visitDate" label="就诊时间" width="200" sortable>
        <template #default="{ row }">
          {{ row.visitDate }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150">
        <template #default="{ row }">
          <el-button size="small" @click="handleView(row)">查看</el-button>
          <el-button size="small" type="danger" @click="handleDelete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 20, 30, 50]"
        :small="false"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

// 表格数据
const tableData = ref([
  {
    trackCode: 'TrackCode 0',
    name: '护卫军',
    idCard: '123123123123737251234',
    phone: '24232434',
    isInitial: false,
    visitDate: '2017-10-31 至 2017-11-31'
  },
  {
    trackCode: 'TrackCode 1',
    name: '李艳梅',
    idCard: '123123123123737251234',
    phone: '32323423',
    isInitial: true,
    visitDate: '2017-10-31 至 2017-11-31'
  },
  // 其他数据...
])

// 分页相关
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(100)

// 排序处理
const handleSortChange = ({ column, prop, order }) => {
  console.log('排序:', prop, order)
  // 这里添加实际的排序逻辑
}

// 分页处理
const handleSizeChange = (val) => {
  console.log(`每页 ${val} 条`)
  pageSize.value = val
  // 这里添加获取新数据的逻辑
}

const handleCurrentChange = (val) => {
  console.log(`当前页: ${val}`)
  currentPage.value = val
  // 这里添加获取新数据的逻辑
}

// 操作按钮处理
const handleView = (row) => {
  console.log('查看:', row)
  // 这里添加查看逻辑
}

const handleDelete = (row) => {
  console.log('删除:', row)
  // 这里添加删除逻辑，可以使用 ElMessageBox 确认
  ElMessageBox.confirm('确定要删除这条记录吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success('删除成功')
  }).catch(() => {
    ElMessage.info('已取消删除')
  })
}
</script>

<style scoped>
.patient-table-container {
  padding: 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.diagnosis-tag {
  display: flex;
  align-items: center;
}

.diagnosis-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.diagnosis-initial {
  background-color: #909399; /* 灰色表示否 */
}

.diagnosis-followup {
  background-color: #67C23A; /* 绿色表示是 */
}
</style>
